using System;
using System.Collections.Generic;
using System.Text;
using WCSFContrib.PageFlow;

namespace PageFlowQuickstart.Modules.Customers.Tests.Mocks
{
    public class MockPageFlow : IPageFlow
    {
        public bool StartCalled = false;
        public string NavigateToTransitionName = null;
        public bool CompleteCalled = false;
        MockPageFlowState _userData = new MockPageFlowState();

        #region IPageFlow Members

        public event EventHandler<PageFlowAbortedEventArgs> Aborted;

        public event EventHandler<PageFlowEventArgs> Started;

        public event EventHandler<PageFlowEventArgs> Completed;

        public event EventHandler<PageFlowEventArgs> Suspended;

        public event EventHandler<PageFlowEventArgs> Resumed;

        public Page CurrentPage
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public IPageFlowDefinition Definition
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public Guid Id
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public PageFlowStatus Status
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public System.Collections.ObjectModel.ReadOnlyCollection<string> Transitions
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public PageFlowState UserData
        {
            get { return _userData; }
        }

        public void Abort(bool redirectToAbortPage)
        {
            OnAborted();
        }

        public bool CanRedirectTo(string pageName)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void Navigate(string transitionName)
        {
            NavigateToTransitionName = transitionName;
        }

        public void RedirectToCurrentPage()
        {            
        }

        public void SetCurrentPage(string pageName)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void Start()
        {
            StartCalled = true;
            OnStarted();
        }

        public void Suspend()
        {
            OnSuspended();
        }

        public void Resume()
        {
            OnResumed();
        }

        public void Complete()
        {
            CompleteCalled = true;
            OnCompleted();
        }

        public void Next()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        private void OnSuspended()
        {
            if (Suspended != null)
                Suspended(this, new PageFlowEventArgs(this));
        }

        private void OnResumed()
        {
            if (Resumed != null)
                Resumed(this, new PageFlowEventArgs(this));
        }

        private void OnCompleted()
        {
            if (Completed != null)
                Completed(this, new PageFlowEventArgs(this));
        }

        private void OnStarted()
        {
            if (Started != null)
                Started(this, new PageFlowEventArgs(this));
        }

        private void OnAborted()
        {
            if (Aborted != null)
                Aborted(this, new PageFlowAbortedEventArgs(new Guid()));
        }
    }
}
